﻿package mortal.game.view.platform.platformTencent
{
    import Message.DB.Tables.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.platform.*;
    import mortal.mvc.core.*;

    public class platformQQLevelCellRender extends GCellRenderer
    {
        private var _itemList:GTileList;
        private var _getBtn:GLoadingButton;
        private var _lvNotReachTxt:GImageBitmap;
        private var _giftData:TPlatformGift;

        public function platformQQLevelCellRender()
        {
            return;
        }// end function

        private function getDataProviderByGiftCode(param1:int) : DataProvider
        {
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_9:PlatformVIPItemGroup = null;
            var _loc_2:* = new DataProvider();
            var _loc_3:* = new ItemData(param1).itemInfo as ItemGiftBagInfo;
            var _loc_4:* = _loc_3.itemList1.split("&");
            var _loc_7:* = _loc_4.length;
            var _loc_8:int = 0;
            while (_loc_8 < _loc_4.length)
            {
                
                _loc_5 = _loc_4[_loc_8].split("#");
                _loc_9 = new PlatformVIPItemGroup();
                _loc_9.itemCode = int(_loc_5[1]);
                _loc_9.itemAmount = _loc_5[2];
                _loc_9.isBind = true;
                _loc_2.addItem(_loc_9);
                _loc_8++;
            }
            return _loc_2;
        }// end function

        private function setCanGetStyle() : void
        {
            this._lvNotReachTxt.visible = false;
            this._getBtn.visible = true;
            this._getBtn.mouseEnabled = true;
            this._getBtn.filters = [];
            EffectManager.glowFilterReg(this._getBtn);
            return;
        }// end function

        private function setCanNotGetStyle() : void
        {
            this._lvNotReachTxt.visible = false;
            this._getBtn.visible = true;
            this._getBtn.mouseEnabled = false;
            EffectManager.glowFilterUnReg(this._getBtn);
            this._getBtn.filters = [FilterConst.colorFilter3];
            return;
        }// end function

        private function setLevelNotReachStyle() : void
        {
            this._getBtn.visible = false;
            this._lvNotReachTxt.visible = true;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._giftData = param1 as TPlatformGift;
            this._itemList.dataProvider = this.getDataProviderByGiftCode(this._giftData.reward);
            this._itemList.x = 54 + 85 - 18 - 43 - 0.5 * (this._itemList.dataProvider.length * 43);
            this._itemList.drawNow();
            var _loc_2:* = UIFactory.gTextField(Language.getStringByParam(90485, this._giftData.lvLimit), 135 + 47, 4, 220, 40, this, GlobalStyle.textFormatBai.setSize(16));
            _loc_2.mouseEnabled = false;
            pushUIToDisposeVec(_loc_2);
            if (PlatformTencentUtil.getLGRTByTPlatformGift(this._giftData) == PlatformVIPGiftGroup.CanReceive)
            {
                this.setCanGetStyle();
            }
            else if (PlatformTencentUtil.getVipLevel() > 0 && !PlatformTencentUtil.isPast() && PlatformTencentUtil.getLGRTByTPlatformGift(this._giftData) == PlatformVIPGiftGroup.UnReceive)
            {
                this.setLevelNotReachStyle();
            }
            else
            {
                this.setCanNotGetStyle();
            }
            if (PlatformTencentUtil.isYellowEnter())
            {
                this.setYellow(param1);
            }
            else if (PlatformTencentUtil.isBlueEnter())
            {
                this.setBlue(param1);
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            if (PlatformTencentUtil.isYellowEnter())
            {
                this.createYellow();
            }
            else if (PlatformTencentUtil.isBlueEnter())
            {
                this.createBlue();
            }
            this._itemList = UIFactory.tileList(54 + 85 - 18 - 43, 8 + 63 - 6, 500, 40, this);
            this._itemList.columnWidth = 43;
            this._itemList.rowHeight = 40;
            this._itemList.setStyle("cellRenderer", PlatformVIPItemCellRender);
            this._itemList.direction = GBoxDirection.HORIZONTAL;
            this._lvNotReachTxt = UIFactory.gImageBitmap(ImagesConst.QQBlueLevelNotReach, 100 + 57, 30 + 53, this);
            this._lvNotReachTxt.visible = false;
            pushUIToDisposeVec(UIFactory.bg(0, 70 - 23, 236, 1, this, ImagesConst.SplitLine));
            return;
        }// end function

        private function setYellow(param1) : void
        {
            var _loc_2:* = new ItemData((param1 as TPlatformGift).reward).name;
            var _loc_3:* = UIFactory.gImageBitmap(ImagesConst.QQYellowLevelGiftTxt, 18, 9, this);
            pushUIToDisposeVec(_loc_3);
            return;
        }// end function

        private function setBlue(param1) : void
        {
            var _loc_2:* = new ItemData((param1 as TPlatformGift).reward).name;
            var _loc_3:* = UIFactory.gImageBitmap(ImagesConst.QQBlueLevelGiftTxt, 18, 9, this);
            pushUIToDisposeVec(_loc_3);
            return;
        }// end function

        private function createYellow() : void
        {
            pushUIToDisposeVec(UIFactory.bg(0, 0, 236, 120, this, ImagesConst.QQYellowBlockBg));
            this._getBtn = UIFactory.gLoadingButton(ResFileConst.QQYellowGetBtn, 120 + 55 - 4, 50 + 25, 64, 29, this);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            return;
        }// end function

        private function createBlue() : void
        {
            pushUIToDisposeVec(UIFactory.bg(0, 0, 236, 120, this, ImagesConst.QQBlueBlockBg));
            this._getBtn = UIFactory.gLoadingButton(ResFileConst.QQBlueGetBtn, 120 + 55 - 4, 50 + 25, 64, 31, this);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            return;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            if (!this._giftData)
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.PlatformRequestQQYellowGift, this._giftData.id));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._itemList)
            {
                this._itemList.dispose(param1);
                this._itemList = null;
            }
            if (this._getBtn)
            {
                this._getBtn.dispose(param1);
                this._getBtn = null;
            }
            if (this._lvNotReachTxt)
            {
                this._lvNotReachTxt.dispose(param1);
                this._lvNotReachTxt = null;
            }
            this._giftData = null;
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
